<html>

<head>
    <title>场景、相机、渲染器</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        canvas {
            width: 100%;
            height: 100%
        }

        #info {
            position: absolute;
            top: 10px;
            width: 100%;
            text-align: center;
            z-index: 100;
            display: block;
            color: #ffffff
        }
    </style>
</head>

<body>
    <div id="info">Description</div>
</body>
<script src="three/build/three.js"></script>
<script>
    //场景
    var scene = new THREE.Scene()
    //摄像机
    var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) //视野角度、长宽比、远剪画面、近剪画面
    //渲染器
    var renderer = new THREE.WebGLRenderer();
    //渲染尺寸
    renderer.setSize(window.innerWidth, window.innerHeight)
    document.body.appendChild(renderer.domElement)

    //------------立方体绘制
    var geometry = new THREE.BoxGeometry(1, 1, 1) // 立方体对象
    var material = new THREE.MeshBasicMaterial({ //材质
        color: 0x00ff00
    })
    var cube = new THREE.Mesh(geometry, material) //网格
    scene.add(cube) //将包含立方体与材质的网格对象放入场景中

    camera.position.z = 5 //移动摄像机

    //-------------绘制线
    var meterial_line = new THREE.LineBasicMaterial({
        color: 0x0000ff
    })
    var geometry_line = new THREE.Geometry()
    geometry_line.vertices.push(new THREE.Vector3(-2, 0, 0))
    geometry_line.vertices.push(new THREE.Vector3(0, 2, 0))
    geometry_line.vertices.push(new THREE.Vector3(2, 0, 0))
    geometry_line.vertices.push(new THREE.Vector3(0, -2, 0))
    geometry_line.vertices.push(new THREE.Vector3(-2, 0, 0))

    var line = new THREE.Line(geometry_line, meterial_line)
    scene.add(line)
 
    //-------------绘制文字
    var loader = new THREE.FontLoader()
    loader.load('three/examples/fonts/helvetiker_regular.typeface.json', function (font) {
        var geometry = new THREE.TextGeometry('Hello three', {
            font: font,
            size: 1,
            height: 0,
            curveSegments: 0,
            // bevelEnabled: true,
            // bevelThickness: 1,
            // bevelSize: 1,
            // bevelSegments: 1
        });
        //创建法向量材质
        var meshMaterial = new THREE.MeshNormalMaterial({
            flatShading: THREE.FlatShading,
            transparent: true,
            opacity: 0.9
        });
        var mesh = new THREE.Mesh(geometry, meshMaterial);
        mesh.position.set(-3, 2.5, 0);
        scene.add(mesh);

    });

    function animate() {
        requestAnimationFrame(animate)
        cube.rotation.x += 0.01
        cube.rotation.y += 0.01
        line.rotation.x += 0.01
        renderer.render(scene, camera) //场景与摄像机渲染
    }
    animate();
</script>

</html>